package chapter03

/**
 * @program lu-scala01
 * @description: 特质混合
 * @author: zhanglu
 * @create: 2022-03-20 22:21:00
 */
object C14_TraitMiXin {

  def main(args: Array[String]): Unit = {
    val student = new Student14
    student.study
    student.increase

    student.play()
    student.increase

    student.dating
    student.increase
  }

}

trait Knowledge{
  var amount: Int = 0
  def increase: Unit
}

class Student14 extends Person13 with Young with Knowledge {

  //重写冲突的属性
  override val name: String = "lu"
  sex = "男"

  //实现抽象方法
  def dating: Unit = {
    println(s"student $name is dating")
  }
  def study: Unit ={
    println(s"student $name is studing")
  }

  override def sayHello(): Unit = {
    super.sayHello()
    println(s"hello from student $name")
  }

  /**
   * 实现特质里面的抽象方法
   */
  override def increase: Unit = {
    amount += 1
    println(s"student $name knowledge increased: $amount")
  }
}
